<?php
/**
 * 教室信息类
 */
namespace app\admin\controller;

use think\App;
use think\facade\View;
use app\admin\model\Organizationmodel;
use app\admin\validate\Student as validate;

class Organization extends Common
{

    public function __construct(App $app)
    {
        $this->validate = validate::class;
        $this->validateType = 'organization';
        $this->localModel = new Organizationmodel();
        parent::__construct($app);
    }

    public function index()
    {
        $where = $showDataArr = [];

        $dataArr = $this->request->request('search/a', []);

        if($dataArr['title'])  $where[] = ['title', 'like', "%".$dataArr['title']."%"];
        if($dataArr['status'])    $where[] = ['status', '=', $dataArr['status']];

        $list = $this->localModel->findAllPageInfo('*', $where, ['id'=>'desc'], $this->request->param());
        $showDataArr = ['data'=>$list['data'], 'pageData'=>$list['page'], 'dataArr'=>$dataArr, 'page'=>$this->request->get('page')];
        View::assign(array_merge($dataArr, $showDataArr));
        return view();
    }

    public function add(){
        $id = $this->request->get('id', 0);
        $where = [['status', '=', 1]];
        if($id)  $where[] = ['id', '<>', $id];
        $showData['oList'] = $this->localModel->findAllInfo('id, title, pid', $where);

        if($id){
            $showData['id'] = $id;
            $showData['detail'] = $this->localModel->findDetaiInfoById('*', $id);
            View::assign($showData);
            return view('edit');
        }else{
            View::assign($showData);
            return view();
        }
    }

}
